void main() {
  //实例化 Person 类
  Person p1 = new Person("小明", 28, '大佬');
  print(p1.name);
  print(p1.age);
  print(p1.job);
  var p = new Person("小明", 20, '小白');
  //使用简写命名构造函数
  Person p2 = Person.person2("小明", 20);
  print(p2.name);
  print(p2.age);
  print(p2.job);


  // p.name = "张三";
  p.age = 20;
  p.job = "程序员";
  p.printInfo();
  p.eat();
  //访问属性
  print({p.name, p.age, p.job});
  //带参数
  p.eatFruit("苹果");
}

class Person {
  String? name;
  int? age;
  String? job;
  // 构造方法
  Person(
    String name,
    int i,
    String s,
  ) {
    this.name = name;
    this.age = i;
    this.job = s;
  }
  //简写构造函数
  Person.person2(this.name, this.age);

  void eat() {
    print("${this.name}正在吃饭");
  }

  void eatFruit(String food) {
    print("${this.name}正在吃${food}");
  }

  void printInfo() {
    print("${this.name}---${this.age}---${this.job}");
  }
}
